﻿Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Web
Imports System.Web.Configuration
Imports System.IO
Imports System.Net

Friend Class UploaderHandler
    Implements IHttpHandler

    'Querystring fields.
    'a - image path.

    Friend ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return True
        End Get
    End Property

    Friend Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
        If context.Request.Files.Count > 0 Then
            Dim i As Integer
            For i = 0 To context.Request.Files.Count - 1 Step 1
                Dim file As HttpPostedFile = context.Request.Files(i)
                Dim fileName As String = Path.GetFileName(file.FileName)
                Dim fileFolder As String = context.Server.MapPath(context.Server.UrlDecode(context.Request.QueryString("a")))

                Dim filePath As String = String.Format("{0}{1}", fileFolder, fileName)
                file.SaveAs(filePath)
            Next
        End If
    End Sub

End Class
